package com.atguigu.gmall.serviceutil.config;

import com.atguigu.gmall.serviceutil.service.OssService;
import com.atguigu.gmall.serviceutil.service.impl.OssServiceImpl;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/8/27 23:35
 */
@EnableConfigurationProperties(AppMinioProperties.class)
@Configuration
public class AppMinioClient {
    @Autowired
    private AppMinioProperties appMinioProperties;

    @Bean
    public MinioClient minioClient() throws Exception {
        //String endpoint 访问地址
        // String accessKey 访问密钥
        // String secretKey 密钥
        MinioClient minioClient = new MinioClient(appMinioProperties.getEndpoint(),
                appMinioProperties.getAccessKey(),
                appMinioProperties.getSecretKey());
        boolean exists = minioClient.bucketExists(appMinioProperties.getBucketName());
        if (!exists){
            minioClient.makeBucket(appMinioProperties.getBucketName());
        }
        return minioClient;
    }
    @Bean
    public OssService ossService(){
        return new OssServiceImpl();
    }
}
